package com.beep.erp.model.stock;


import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.beep.erp.AppContext;
import com.beep.erp.Constants;
import com.beep.erp.R;
import com.beep.erp.common.base.BaseFragment;
import com.beep.erp.common.base.simpleactivity.SimpleBackActivity;
import com.beep.erp.common.base.simpleactivity.SimpleBackPage;
import com.beep.erp.common.utils.SPUtils;
import com.beep.erp.common.utils.ToastUtils;
import com.beep.erp.model.earlystage.scan.ScanActivity;
import com.beep.erp.model.login.LoginActivity;
import com.beep.erp.model.stockIn.StockInListActivity;
import com.beep.erp.model.transfer.TransferActivity;

import butterknife.BindView;

import static com.beep.erp.AppContext._context;

/**
 * A simple {@link Fragment} subclass.
 */
public class StockFragment extends BaseFragment<StockPresenter, StockModel> implements StockContract.View, StockAdapter.OnItemClickLitener {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.appbar_layout)
    AppBarLayout appbarLayout;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.find)
    RecyclerView find;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_stock;
    }

    @Override
    protected void initView(View view) {
        tvTitle.setText(R.string.main_tab_name_order);
        StockAdapter findAdapter = new StockAdapter(getActivity());
        findAdapter.setOnItemClickLitener(this);
        find.setLayoutManager(new LinearLayoutManager(getActivity()));
        find.setHasFixedSize(true);
        find.setAdapter(findAdapter);
    }

    @Override
    protected void lazyLoad() {

    }

    @Override
    public void onItemClick(View view, int position) {
        if (AppContext.getInstance().isLogin()) {
            switch (position) {
                case 0:
                    //采购单
                    SimpleBackActivity.showSimpleBack(getActivity(), SimpleBackPage.ENTRUST);
                    break;
                case 1:
                    //入库单
                    StockInListActivity.start(getActivity());
                    break;
                case 2:
                    //移库
                    TransferActivity.start(getActivity());
                    break;
                case 3:
                    //期出期入
                    SimpleBackActivity.showSimpleBack(getActivity(), SimpleBackPage.RERLYSTAGE);
                    break;
                case 4:
                    //出库
                    ScanActivity.start(getActivity(), "", true);
                    break;
                default:
                    break;
            }
        } else {
            LoginActivity.start(getActivity());
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(String message) {
        ToastUtils.showShort(message);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

}
